package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
@Api("套餐相关接口")
public class SetmealController {

    @Autowired
    SetmealService setmealService;
    @PostMapping
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }


    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result querySetmealById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.querySetmealById(id);
        return Result.success(setmealVO);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result querySetmealPage(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = setmealService.querySetmealPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @ApiOperation("套餐起售禁售")
    @PostMapping("/status/{status}")
    public Result setmealStartus(@PathVariable("status") Integer status, Long id){
        setmealService.updateSetmealStatus(status,id);
        return Result.success( );
    }

    @ApiOperation("修改套餐")
    @PutMapping
    public Result putSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);
        return Result.success( );
    }
}
